Typical Usage:
Required bean name is "SS1".
The following three typical usage modes are:
(1)
The easiest usage of the bean is a communication without interrupts (polling mode). This example
works as a repeater - the received character will be sent back.
MAIN.C
SS1_TComData ch;
byte err;
void main(void)
{
for (;;) {
while (SS1_GetCharsInRxBuf() == 0); //Wait for a character
err = SS1_RecvChar(&ch); // Get received character
if ( (err == ERR_OK) || (err == ERR_OVERRUN) );
SS1_SendChar(ch); // Prepare a character for transmision
}
}
(2)
The second typical usage of this bean is a communication with interrupts using communication
events.
EVENTS.C
void AM1_OnRxChar(void)
{
SS1_TComData ch;
byte err;
err = SS1_RecvChar(&ch); // Get received character
if ( (err == ERR_OK) || (err == ERR_OVERRUN) )
SS1_SendChar(ch); // Prepare a character for transmision
}
(3)
The following example shows how to recognize a communication error using the GetError method.
In interrupt communication mode the user can use the OnError event to recognize the error during
communication.
MAIN.C
SS1_TComData ch;
byte err;
void main(void)
{
for (;;) {
while (SS1_GetCharsInRxBuf() == 0); //Wait for a character
err = SS1_RecvChar(&ch); // Get received character
if ( (err == ERR_OK) || (err == ERR_OVERRUN) );
SS1_SendChar(ch); // Prepare a character for transmision
}
}
EVENTS.C
void SS1_OnError(void)
{
SS1_TError error; //TError union is defined in the header file
/* Read the last communication errors */
SS1_GetError(&error);
/* If error OverRun occured then ... */
if(error.errName.OverRun) {
:
}
}
(4)
The next typical usage of this bean is a communication using DMA transfer. Interrupts can be enabled or disabled.
This typical usage can be used on derivatives with DMA controller.
MAIN.C
#define BLOCK_LENGTH 10
SS1_TComData SampleBlock[BLOCK_LENGTH];
word Snt, Rcv;
void main(void)
{
:
/* Enable DMA transfer from the receiver */
(void)SS1_RecvBlock(&SampleBlock[0],BLOCK_LENGTH,&Rcv);
/* Send block of samples using DMA support */
(void)SS1_SendBlock(&SampleBlock[0],BLOCK_LENGTH,&Snt);
/* Wait for transmit/receive BLOCK_LENGTH samples */
/* Note: It is clocked by master (SynchroMaster) */
while (SS1_GetCharsInRxBuf() < BLOCK_LENGTH) {};
:
}
For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.
|